package com.yoo.ons.function.settings

import android.content.Context
import android.content.Intent
import com.google.gson.Gson
import com.yoo.ons.model.PolicyModel
import com.yoo.chat.kit.activity.RongWebviewActivity
import com.yoo.chat.kit.utils.StatusBarUtil
import com.yoo.module_base.utils.SaveDeviceUtil
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.ons.base.BaseVMActivity
import com.yoo.ons.databinding.ActivitySettingsBinding
import com.yoo.ons.function.account.MyAccountActivity
import com.yoo.ons.function.settings.viewmodel.SettingsViewModel

class SettingsActivity:BaseVMActivity<ActivitySettingsBinding, SettingsViewModel>(ActivitySettingsBinding::inflate,SettingsViewModel::class.java) {


    override fun initView() {
        super.initView()
        binding.myAccountContainer.setOnClickCallback {
            MyAccountActivity.start(this)
        }
        // 将字符串转换为 PolicyModel 对象
        val policyModelFromJson =
            Gson().fromJson(SaveDeviceUtil.getPolicyUrl(), PolicyModel::class.java)

        binding.privacyPolicyContainer.setOnClickCallback {
            val intent = Intent(this, RongWebviewActivity::class.java)
            intent.putExtra("isFull", true)
            intent.putExtra("url", policyModelFromJson.privacyPolicy)
            intent.putExtra(
                "title",
                resources.getString(com.yoo.module_res.R.string.privacy_policy)
            )
            startActivity(intent)
        }
        binding.termsContainer.setOnClickCallback {
            val intent = Intent(this, RongWebviewActivity::class.java)
            intent.putExtra("isFull", true)
            intent.putExtra("url", policyModelFromJson.privacyPolicy)
            intent.putExtra("title", resources.getString(com.yoo.module_res.R.string.terms))
            startActivity(intent)
        }
        binding.titleBar.setTitleText(getString(com.yoo.module_res.R.string.settings))
        binding.titleBar.setTitleBarPadding(StatusBarUtil.getStatusBarHeight(this))
        binding.titleBar.setBackListener { finish() }
    }

    override fun initData() {

    }
    companion object {

        fun start(context: Context?) {
            val intent = Intent(context, SettingsActivity::class.java)
            context?.startActivity(intent)
        }
    }
}